<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块化编程</title>
</head>
<body>
    
</body>
</html>

<script>

    let module = (function(){
        //模块列表集合
        const moduleLists = {};
        function define(name,modules,action){
            modules.map((m,i) => {
                modules[i] = moduleLists[m];
            });
            //执行并保存模块
            moduleLists[name] = action.apply(null,modules);
        }
        return {define};
    })();


    //声明模块不依赖其他模块
    module.define("hd",[],function(){
        return {
            show(){
                console.log("hd module show");
            }
        };
    });

    //声明模块时依赖其他模块
    module.define("xj",["hd"],function(hd){
        hd.show();
    });


    

    



</script>